package com.example.imoocmusicdemo.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.imoocmusicdemo.R;
import com.example.imoocmusicdemo.activitys.PlayMusicActivity;

public class MusicListAdapter extends RecyclerView.Adapter<MusicListAdapter.ViewHolder> {

    private Context mContext;

    public MusicListAdapter (Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    public MusicListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_list_music, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MusicListAdapter.ViewHolder viewHolder, int i) {

        Glide.with(mContext)
                .load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F052420110515%2F200524110515-2-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1655216439&t=0a507ebbff654e7b39345ced0a28c1a8")
                .into(viewHolder.iv1Icon);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(mContext, PlayMusicActivity.class);
                mContext.startActivity(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    class  ViewHolder extends RecyclerView.ViewHolder {

        View itemView;
        ImageView iv1Icon;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            this.itemView = itemView;
            iv1Icon = itemView.findViewById(R.id.iv1_icon);
        }
    }
}
